import ReactDOM from 'react-dom';

export default class UIUtil
{
    // 更新component的高度，（因为有的第三方组件不支持通过`props`来传递样式）
    static updateComponentHeight(ref, height)
    {
        if(ref)
        {
            let div = ReactDOM.findDOMNode(ref);
            if(div)
            {
                div.style.height = (typeof height === 'string') ? height : (height + 'px');
            }
        }
    }
    // 修复列表数据量少时，下拉刷新时列表被遮挡的问题
    static fixListViewHeightIssue(listView, minHeight)
    {
        if(!listView)
        {
            return;
        }
        minHeight = (typeof minHeight === 'string') ? minHeight : (minHeight + 'px');
        let listViewDiv = ReactDOM.findDOMNode(listView);
        let es = listViewDiv.getElementsByClassName('am-list-view-scrollview-content');
        if(es && es.length > 0)
        {
            es[0].style.minHeight = minHeight;
        }
        es = listViewDiv.getElementsByClassName('am-pull-to-refresh-content-wrapper');
        if(es && es.length > 0)
        {
            es[0].style.minHeight = minHeight;
        }
    }

    static fixCalendarHeightIssue(calendarView, height)
    {
        if(!calendarView)
        {
            return;
        }
        height = (typeof height === 'string') ? height : (height + 'px');
        let calendarViewDiv = ReactDOM.findDOMNode(calendarView);
        let es = calendarViewDiv.getElementsByClassName('content');
        if(es && es.length > 0)
        {
            es[0].style.height = height;
        }
    }
}